home *** CD-ROM | disk | FTP | other *** search
/ Hottest 6 / Hottest 6 (1996)(PDSoft)[!].iso / software / fredfish / 1092.lha / Programs / ErrorMsg / Examples / ScanIFF.s < prev    next >
Text File  |  1994-12-21  |  6KB  |  286 lines

  1.     opt    AMIGA
  2.  
  3. ;* $Revision Header built automatically *************** (do not edit) ************
  4. ;*
  5. ;* © Copyright by F.Delacroix
  6. ;*
  7. ;* File             : DH0{42MB}:Progs/ErrorMsg/Examples/ScanIFF.s
  8. ;* Created on       : Jeudi, 27-Oct-94   21:12:46
  9. ;* Created by       : Frédéric Delacroix
  10. ;* Current revision : V1.00
  11. ;*
  12. ;*
  13. ;* Purpose
  14. ;* -------
  15. ;*     This is an example for programming errormsg.library, it is
  16. ;*     public domain. Its job is to scan an IFF file and list all
  17. ;*     the chunks it contains. Use from CLI only. Added for V3.02
  18. ;*     on request by B.Beauchamp and F.Jardillier.
  19. ;*
  20. ;* Revision V1.00
  21. ;* --------------
  22. ;*     --- Initial release ---
  23. ;*
  24. ;*********************************************************************************
  25. REVISION  MACRO
  26.           dc.b "1.00"
  27.           ENDM
  28. REVDATE   MACRO
  29.           dc.b "27-Oct-94"
  30.           ENDM
  31. REVTIME   MACRO
  32.           dc.b "21:12:46"
  33.           ENDM
  34. AUTHOR    MACRO
  35.           dc.b "Frédéric Delacroix"
  36.           ENDM
  37. VERNUM    EQU  01
  38. REVNUM    EQU  00
  39.  
  40.     include    exec/execbase.i
  41.     include    dos/dosasl.i
  42.     include    libraries/errormsg.i
  43.     include    libraries/errormsg_lib.i
  44.     include    libraries/iffparse.i
  45.     include    libraries/iffparse_lib.i
  46.  
  47. Start    move.l    4.w,a6
  48.     move.l    ThisTask(a6),a4
  49.     tst.l    pr_CLI(a4)
  50.     bne.s    .FromCLI
  51.     lea    pr_MsgPort(a4),a0
  52.     jsr    _LVOWaitPort(a6)
  53.     lea    pr_MsgPort(a4),a0
  54.     jsr    _LVOGetMsg(a6)
  55.     move.l    d0,WB.Startup
  56.     bra.s    .Exit
  57. .FromCLI
  58.     move.l    a6,Exec.Base
  59.     lea    ErrorMsg.Name(pc),a1
  60.     moveq    #4,d0    ; we use ermOpenLibraryIDA() => version 4 !
  61.     jsr    _LVOOpenLibrary(a6)
  62.     move.l    d0,ErrorMsg.Base
  63.     beq.s    .Exit
  64.     move.l    #ERMSYS_IFFPARSE,d1
  65.     moveq    #37,d0
  66.     lea    IFFParse.Base(pc),a0
  67.     bsr.s    OpenLibID
  68.     beq.s    .CloseERM
  69.  
  70.     bsr.s    ReadArgs
  71.     beq.s    .CloseIFFParse
  72.     bsr    Scan
  73.     bsr    FreeArgs
  74.  
  75. .CloseIFFParse
  76.     move.l    IFFParse.Base(pc),a1
  77.     jsr    _LVOCloseLibrary(a6)
  78. .CloseERM
  79.     move.l    ErrorMsg.Base(pc),a1
  80.     jsr    _LVOCloseLibrary(a6)
  81. .Exit    move.l    WB.Startup(pc),d0
  82.     beq.s    .ToCLI
  83.     jsr    _LVOForbid(a6)
  84.     move.l    d0,a1
  85.     jsr    _LVOReplyMsg(a6)
  86. .ToCLI    moveq    #0,d0
  87.     rts
  88.  
  89. OpenLibID    ; (D0,Z)Base=OpenLib(LibID,Version,Storage)(D1,D0,A0)
  90.     movem.l    a2/a6,-(sp)
  91.     suba.l    a2,a2
  92.     move.l    ErrorMsg.Base(pc),a6
  93.     jsr    _LVOermOpenLibraryIDA(a6)
  94. .Good    movem.l    (sp)+,a2/a6
  95.     rts
  96.  
  97. PrintError    ; PrintError(Code,System,Subsystem)(D0,D1,D2)
  98.     move.l    a6,-(sp)
  99.     move.l    ErrorMsg.Base(pc),a6
  100.     tst.l    Req.Arg
  101.     bne.s    .Req
  102.     lea    ScanIFF.Name(pc),a0
  103.     jsr    _LVOPutErrorMsg(a6)
  104.     bra.s    .Done
  105. .Req    suba.l    a0,a0
  106.     jsr    _LVODisplayErrorMsgA(a6)
  107. .Done    move.l    (sp)+,a6
  108.     rts
  109.  
  110. ReadArgs    ; (Z=1)Success=ReadArgs()
  111.     movem.l    d2-d3/a6,-(sp)
  112.     move.l    ErrorMsg.Base(pc),a6
  113.     move.l    emb_DOSBase(a6),a6
  114.     move.l    #Args.Template,d1
  115.     move.l    #Args.Array,d2
  116.     moveq    #0,d3
  117.     jsr    _LVOReadArgs(a6)
  118.     move.l    d0,Args.RDArgs
  119.     bne.s    .OK
  120.     move.l    #ERMSYS_DOS,d1
  121.     move.l    #ERMSUB_IoErr,d2
  122.     bsr    PrintError
  123.     moveq    #0,d0
  124. .OK    movem.l    (sp)+,d2-d3/a6
  125.     rts
  126.  
  127. FreeArgs    ; FreeArgs()
  128.     move.l    a6,-(sp)
  129.     move.l    ErrorMsg.Base(pc),a6
  130.     move.l    emb_DOSBase(a6),a6
  131.     move.l    Args.RDArgs(pc),d1
  132.     jsr    _LVOFreeArgs(a6)
  133.     move.l    (sp)+,a6
  134.     rts
  135.  
  136. Scan    ; Scan()
  137.     movem.l    d2-d3/a4/a6,-(sp)
  138.     move.l    IFFParse.Base(pc),a6
  139.     jsr    _LVOAllocIFF(a6)
  140.     move.l    d0,a4
  141.     move.l    a4,d0
  142.     bne.s    .HandleOK
  143.     move.l    #ERMSYS_EXEC,d1
  144.     move.l    #ERMSUB_NoMemory,d2
  145.     bsr    PrintError
  146.     bra    .Ret
  147. .HandleOK
  148.     move.l    a4,a0
  149.     jsr    _LVOInitIFFasDOS(a6)
  150.  
  151.     move.l    ErrorMsg.Base(pc),a6
  152.     move.l    emb_DOSBase(a6),a6
  153.     move.l    FileName.Arg(pc),d1
  154.     move.l    #MODE_OLDFILE,d2
  155.     jsr    _LVOOpen(a6)
  156.     move.l    d0,iff_Stream(a4)
  157.     bne.s    .FileOK
  158.     move.l    #ERMSYS_DOS,d1
  159.     move.l    #ERMSUB_IoErr,d2
  160.     bsr    PrintError
  161.     bra    .FreeHandle
  162. .FileOK
  163.     move.l    IFFParse.Base(pc),a6
  164.     move.l    a4,a0
  165.     move.l    #IFFF_READ,d0
  166.     jsr    _LVOOpenIFF(a6)
  167.     tst.l    d0
  168.     beq.s    .OpenOK
  169.     move.l    #ERMSYS_IFFPARSE,d1
  170.     move.l    #ERMSUB_Generic,d2
  171.     bsr    PrintError
  172.     bra    .CloseFile
  173. .OpenOK    moveq    #0,d3
  174. .Loop    move.l    a4,a0
  175.     move.l    #IFFPARSE_STEP,d0
  176.     jsr    _LVOParseIFF(a6)
  177.     cmp.l    #IFFERR_EOF,d0
  178.     beq    .End
  179.     tst.l    d0
  180.     beq.s    .Push
  181.     cmp.l    #IFFERR_EOC,d0
  182.     beq.s    .Pop
  183.     move.l    #ERMSYS_IFFPARSE,d1
  184.     move.l    #ERMSUB_Generic,d2
  185.     bsr    PrintError
  186.     bra    .End
  187. .Pop    subq.l    #1,d3    ; ident amount
  188.     bsr    CheckBreak
  189.     beq    .Loop
  190.     move.l    #ERROR_BREAK,d0
  191.     move.l    #ERMSYS_DOS,d1
  192.     move.l    #ERMSUB_IoErr,d2
  193.     bsr    PrintError
  194.     bra.s    .End
  195. .Push    move.l    a4,a0
  196.     jsr    _LVOCurrentChunk(a6)
  197.     move.l    d0,a0
  198.     move.l    a0,d0
  199.     beq.s    .Loop
  200.     bsr    Indent
  201.     beq.s    .DOSError
  202.     move.l    cn_ID(a0),ID.MSG
  203.     move.l    cn_Type(a0),Type.MSG
  204.     move.l    cn_Size(a0),-(sp)
  205.     pea    Type.MSG
  206.     pea    ID.MSG
  207.     move.l    #Chunk.Fmt,d1
  208.     move.l    sp,d2
  209.     move.l    ErrorMsg.Base(pc),a6
  210.     move.l    emb_DOSBase(a6),a6
  211.     jsr    _LVOVPrintf(a6)
  212.     add.l    #12,sp
  213.     addq.l    #1,d3
  214.     move.l    IFFParse.Base(pc),a6
  215.     cmp.l    #-1,d0
  216.     bne    .Loop
  217. .DOSError
  218.     move.l    #ERMSYS_DOS,d1
  219.     move.l    #ERMSUB_IoErr,d2
  220.     clr.l    Req.Arg
  221.     bsr    PrintError
  222. .End    move.l    a4,a0
  223.     move.l    IFFParse.Base(pc),a6
  224.     jsr    _LVOCloseIFF(a6)
  225. .CloseFile
  226.     move.l    iff_Stream(a4),d1
  227.     move.l    ErrorMsg.Base(pc),a6
  228.     move.l    emb_DOSBase(a6),a6
  229.     jsr    _LVOClose(a6)
  230.     ; I ignore the return value from Close(), as this function is
  231.     ; very unlikely to fail for read accesses
  232. .FreeHandle
  233.     move.l    a4,a0
  234.     move.l    IFFParse.Base(pc),a6
  235.     jsr    _LVOFreeIFF(a6)
  236. .Ret    movem.l    (sp)+,d2-d3/a4/a6
  237.     rts
  238.  
  239. Indent    ; (Z=0)Success=Indent(Number)(D3)
  240.     movem.l    d0-d1/d3/a0-a1/a6,-(sp)
  241.     move.l    ErrorMsg.Base(pc),a6
  242.     move.l    emb_DOSBase(a6),a6
  243.     bra.s    .Begin
  244. .Loop    move.l    #Indent.MSG,d1
  245.     jsr    _LVOPutStr(a6)
  246.     eor.l    #-1,d0
  247.     beq.s    .Ret
  248. .Begin    dbra    d3,.Loop
  249.     moveq    #-1,d0    ; clear Z
  250. .Ret    movem.l    (sp)+,d0-d1/d3/a0-a1/a6
  251.     rts
  252.  
  253. CheckBreak    ; (Z=0)Break=CheckBreak()
  254.     movem.l    d0-d1/a0-a1/a6,-(sp)
  255.     move.l    #SIGBREAKF_CTRL_C,d1
  256.     move.l    ErrorMsg.Base(pc),a6
  257.     move.l    emb_DOSBase(a6),a6
  258.     jsr    _LVOCheckSignal(a6)
  259.     tst.l    d0
  260.     movem.l    (sp)+,d0-d1/a0-a1/a6
  261.     rts
  262.  
  263. WB.Startup    dc.l    0
  264. Exec.Base    dc.l    0
  265. ErrorMsg.Base    dc.l    0
  266. IFFParse.Base    dc.l    0
  267.  
  268. Args.Array
  269. FileName.Arg    dc.l    0
  270. Req.Arg    dc.l    0
  271.  
  272. Args.RDArgs    dc.l    0
  273.  
  274. Indent.MSG    dc.b    ' > ',0
  275. ScanIFF.Name    dc.b    'ScanIFF',0
  276.     even
  277. Type.MSG    dc.l    0
  278.     dc.b    0
  279.     even
  280. ID.MSG    dc.l    0
  281.     dc.b    0
  282. Chunk.Fmt    dc.b    'ID: %s  Type: %s (%ld bytes)',10,0
  283.  
  284. Args.Template    dc.b    'FILE/A,REQ/S',0
  285. ErrorMsg.Name    dc.b    'errormsg.library',0
  286.